<?php
/**
 *  View that outputs JSON
 *
 */
class Yz_View_JSON
    extends Yz_View_Abstract
    implements Yz_View_Interface
{

    /**
     *  @var Yz_Hash
     *  default to an empty array so that there be no errors
     */
    protected $json;
    /**
     *  @var string
     */
    protected $text = '{/* View_JSON: No values */}';



    /** get the text (string) content of the view
     *  @return string
     */
    public function getContent()
    {
        if (null === $this->json) {
            return $this->text;
        }
        return json_encode($this->json->toArray());
    }

    /**
     *
     */
    public function setJSON( $json )
    {
        $this->json = new Yz_Hash($json);
        return $this;
    }


    public function render(Yz_HTTP_Response_Interface $rs)
    {
        $rs->setContentType('text/plain; charset=utf-8');
        return parent::render($rs);
    }

} // class
